

/*
	This file is part of SRServerLibrary.
	Foobar is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	SRServerLibrary is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with SRServerLibrary.  If not, see <http://www.gnu.org/licenses/>.
*/



#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>
#include <SRMessenger.h>
#include <SRMessenger.cpp>


int init_suite_SRMessenger(void)
 {
   return 0;
 }

int clean_suite2(void)
 {
  return 0;
 }


//! Test for the SRMEssenger::internalBroadcast(char* message) method
/*! Tests that the function actually broadcasts the message to the loaded plugin(s)
 	SETUP: a. create a new SRPluginLoader instance
		b. load the vlc plugin
		c. start playing a sample video file
		d. broadcast the "pause" command
		e. check the the playback has been paused
*/
void testinternalBroadcast()
 {
	SRPluginLoader *loader = new SRPluginLoader("../../../clisrserver/plugins/vlc/plugin.so");
	SRMessenger* mess = new SRMessenger(loader);
	SRPlugin* plug = loader -> getLastPlugin();
	loader -> exec("play", plug);
	CU_ASSERT(mess -> internalBroadcast("pause") == "done pause");
 }



int main()
 {
   CU_pSuite pSuite = NULL;

   /* initialize the CUnit test registry */
   if (CUE_SUCCESS != CU_initialize_registry())
      return CU_get_error();

   /* add a suite to the registry */
   pSuite = CU_add_suite("Suite_SRMessenger", init_suite_SRMessenger, clean_suite2);
   if (NULL == pSuite) {
      CU_cleanup_registry();
      return CU_get_error();
   }

   /* add the tests to the suite */
   if ((NULL == CU_add_test(pSuite, "test of testInternalBroadcast()", testinternalBroadcast)))
   {
      CU_cleanup_registry();
      return CU_get_error();
   }

   /* Run all tests using the CUnit Basic interface */
   CU_basic_set_mode(CU_BRM_VERBOSE);
   CU_basic_run_tests();
   CU_cleanup_registry();
   return CU_get_error();
 }
